package com.dinggao.crossgo.module.roadbook.activity;

import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.dinggao.crossgo.R;
import com.dinggao.crossgo.core.base.BaseActivity;
import com.dinggao.crossgo.core.observer.EventIntet;
import com.dinggao.crossgo.core.observer.EventMsg;
import com.dinggao.crossgo.core.observer.PrivateObserver;
import com.dinggao.crossgo.core.ui.HackyViewPager;
import com.dinggao.crossgo.core.util.LogUtils;
import com.dinggao.crossgo.module.roadbook.adapter.SamplePagerAdapter;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;

public class RoadBookPublishImageActivity extends BaseActivity implements PrivateObserver {


    @BindView(R.id.viewpager_imageshow)
    HackyViewPager viewpager;
    @BindView(R.id.choose_num_text)
    TextView chooseText;


    private ArrayList<String> imageurl;

    @Override
    protected int getLayoutResource() {
        return R.layout.activity_road_book_publish_image;
    }

    @Override
    protected void onInitialization(Bundle bundle) {
        EventIntet.getDefault().register(this);
        imageurl = getIntent().getStringArrayListExtra("imageurl");
        int position = getIntent().getExtras().getInt("position");
        SamplePagerAdapter adapter = new SamplePagerAdapter(imageurl);
        viewpager.setAdapter(adapter);
        viewpager.setCurrentItem(position);
        viewpager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
                chooseText.setText(position + 1 + "/" + imageurl.size());
            }

            @Override
            public void onPageSelected(int position) {

            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });


    }


    @Override
    protected void onDestroy() {
        super.onDestroy();
        EventIntet.getDefault().unregister(this);
    }

    @Override
    public void update(Object obj) {
        if (!(obj instanceof EventMsg)) {
            return;
        }
        EventMsg eventMsg = (EventMsg) obj;

        //  LogUtils.e("TAG",eventMsg.getMsg()+"-_-"+eventMsg.getFrom()+"-_-"+eventMsg.getCode());
        if (eventMsg.getCode() == 10086) {
            LogUtils.e("eventMsg", "!!!!!" + "!!!!");
            finish();
        }

    }
}
